import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";
// const username = localStorage.getItem("username");

const store = createStore({
  state: {
    username: "",
    sex: "",
    // 左侧菜单是否收起
    isFold: false,
  },
  mutations: {
    setUsername(state, username) {
      state.username = username;
      state.sex = "女";
      //   localStorage.setItem("username", username);
    },
    toggleIsFold(state) {
      state.isFold = !state.isFold;
    },
  },
  // 永久存储化
  plugins: [
    createPersistedState({
      // 额外配置
      // 指定本地存储使用什么： 默认是 window.localStorage
      storage: window.sessionStorage,

      // 指定对那的 state 做存储
      reducer: (state) => {
        return {
          username: state.username,
        };
      },
    }),
  ],
});
export default store;
